package com.masblearn;

import com.masblearn.decorator.RectDecorator;

/**
 * 模式开火方法
 */
public class DefaultFireStrategy implements FireStrategy {
    private final static DefaultFireStrategy DEFAULT_FIRE_STRATEGY = new DefaultFireStrategy();

    private DefaultFireStrategy() {

    }

    public static DefaultFireStrategy getInstance() {
        return DEFAULT_FIRE_STRATEGY;
    }

    @Override
    public void fire(Tank tank) {
        int bx, by;
//       GameModel.getInstance().add(new RectDecorator(new Bullet(bx,by,)));
        switch (tank.dir) {
            case UP:
                bx = tank.x + Tank.TANK_WIDTH / 2 - Bullet.WIDTH / 2;
                by = tank.y - Bullet.HEIGHT / 2;
                //
//                GameModel.getInstance().add(new RectDecorator(new Bullet(bx, by, tank.dir, tank.group)));
                GameModel.getInstance().add(new Bullet(bx, by, tank.dir, tank.group));
                break;
            case DOWN:
                bx = tank.x + Tank.TANK_WIDTH / 2 - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT - Bullet.HEIGHT / 2;
//                GameModel.getInstance().add(new RectDecorator(new Bullet(bx, by, tank.dir, tank.group)));
                GameModel.getInstance().add(new Bullet(bx, by, tank.dir, tank.group));
                break;
            case LEFT:
                bx = tank.x - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT / 2 - Bullet.HEIGHT / 2;
//                GameModel.getInstance().add(new RectDecorator(new Bullet(bx, by, tank.dir, tank.group)));
                GameModel.getInstance().add(new Bullet(bx, by, tank.dir, tank.group));
                break;
            case RIGHT:
                bx = tank.x + Tank.TANK_WIDTH - Bullet.WIDTH / 2;
                by = tank.y + Tank.TANK_HEIGHT / 2 - Bullet.HEIGHT / 2;
//                GameModel.getInstance().add(new RectDecorator(new Bullet(bx, by, tank.dir, tank.group)));
                GameModel.getInstance().add(new Bullet(bx, by, tank.dir, tank.group));
                break;
            default:
                break;
        }
    }
}
